package com.antaohua.tools.framework.base.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.antaohua.tools.framework.base.exception.DeleteEntityException;
import com.antaohua.tools.framework.base.exception.InsertEntityException;
import com.antaohua.tools.framework.base.exception.QureyEntityException;
import com.antaohua.tools.framework.base.exception.UpdateEntityException;
import com.antaohua.tools.framework.base.interfase.BaseDaoInterface;
import com.antaohua.tools.framework.base.interfase.BaseServiceInterface;
import com.antaohua.tools.framework.base.model.UUIDIdentityModel;
import com.antaohua.tools.framework.base.utils.PageUtil;

public class BaseService<E extends UUIDIdentityModel> implements BaseServiceInterface<E>{

	@Autowired
	protected BaseDaoInterface<E> dao;

	@Override
	@Transactional
	public E save(E entity) throws InsertEntityException {
		
		return dao.save(entity);
	}

	@Override
	@Transactional
	public List<E> save(List<E> entitys) throws InsertEntityException {

		return dao.save(entitys);
	}

	@Override
	@Transactional
	public E update(E entity) throws UpdateEntityException {
		
		return dao.update(entity);
	}

	@Override
	@Transactional
	public List<E> update(List<E> entitys) throws UpdateEntityException {
		
		return dao.update(entitys);
	}

	@Override
	@Transactional
	public void delete(E entity) throws DeleteEntityException {
		
		dao.delete(entity);
	}

	@Override
	@Transactional
	public Integer deleteById(String id) throws DeleteEntityException {
		
		return dao.deleteById(id);
	}

	@Override
	@Transactional
	public Integer deleteByIds(List<String> ids) throws DeleteEntityException {
		
		return dao.deleteByIds(ids);
	}

	@Override
	@Transactional
	public Integer deleteByProperty(Map<String, Object> propertys) throws DeleteEntityException {
		
		return dao.deleteByProperty(propertys);
	}

	@Override
	@Transactional
	public Integer deleteByProperty(String propertyName, Object propertyValue) throws DeleteEntityException {
		
		return dao.deleteByProperty(propertyName, propertyValue);
	}

	@Override
	@Transactional(readOnly=true)
	public E findById(String id) throws QureyEntityException {
		
		return dao.findById(id);
	}

	@Override
	@Transactional(readOnly=true)
	public List<E> findByIds(List<String> ids) throws QureyEntityException {
		
		return dao.findByIds(ids);
	}

	@Override
	@Transactional(readOnly=true)
	public PageUtil<E> findAll(PageUtil<E> page) throws QureyEntityException {
		
		return dao.findAll(page);
	}

	@Override
	@Transactional(readOnly=true)
	public List<E> findAll() throws QureyEntityException {
		
		return dao.findAll();
	}

	@Override
	@Transactional(readOnly=true)
	public List<E> findByProperty(String propertyName, Object value) throws QureyEntityException {
		
		return dao.findByProperty(propertyName, value);
	}

	@Override
	@Transactional(readOnly=true)
	public List<E> findByProperty(Map<String, Object> propertys) throws QureyEntityException {
		
		return dao.findByProperty(propertys);
	}

	@Override
	@Transactional(readOnly=true)
	public Long countByProperty(String propertyName, Object value) throws QureyEntityException {
		
		return dao.countByProperty(propertyName, value);
	}

	@Override
	@Transactional(readOnly=true)
	public Long countByProperty(Map<String, Object> propertys) throws QureyEntityException {
		
		return dao.countByProperty(propertys);
	}

	@Override
	@Transactional(readOnly=true)
	public Long countAll() throws QureyEntityException {
		
		return dao.countAll();
	}

	@Override
	@Transactional(readOnly=true)
	public Boolean isExistence(String propertyName, Object value) throws QureyEntityException {
		
		return dao.isExistence(propertyName, value);
	}
	
	
	

}
